package com.clement.spring.study.repository;

import com.clement.spring.study.mapper.BookMapper;
import com.clement.spring.study.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Repository;

/**
 * Created by Clement on 2017/2/27.
 */
@Repository
public class BookDaoImpl implements BookDao {
    private BookMapper bookMapper;
    private MessageSource messageSource;

    @Autowired
    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    @Autowired
    @Override
    public void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    @Override
    public Book getBookById(String id) throws Exception {
//        if (StringUtils.isEmpty(id))
//            throw  new NullPointerException() {
//                @Override
//                public String getMessage() {
//                    return messageSource.getMessage("argument.required",new Object[]{"id"},Locale.CHINESE);
//                }
//            };
        return bookMapper.getBookById(id);
    }
}
